package com.spring.springboot.util;

import java.text.DecimalFormat;

/**
 * @author yizhousong
 * @date 2019/10/23
 * @description: 米转千米
 */
public class DistanceComputeUtil {
    public static void main(String[] args) {
        String s = "13814000";
        String distanceCompute = DistanceComputeUtil.distanceCompute(s);
        System.out.println(distanceCompute);
    }

    public static String distanceCompute(String s) {
        DecimalFormat decimalFormat = new DecimalFormat("###.0");
        if (Double.compare(Double.parseDouble(s), Double.parseDouble("1000")) < 0) {
            return s + "m";
        }
        String format = decimalFormat.format(Double.parseDouble(s) / 1000d);
        if (format.endsWith("0")) {
            return format.substring(0, format.length() - 2) + "Km";
        } else {
            return format + "Km";
        }
    }
}
